#include "stdafx.h"
#include "MainMenu.h"
#include "GamePlay.h"
#include "SceneManager.h"

#include "Vertex.h"
#include "Shader.h"


Shader* shader;
GLuint vboId;

MainMenu::MainMenu()
: Scene()
{}

MainMenu::~MainMenu()
{
	SAFE_DEL(shader);
}

__INT8 MainMenu::Init()
{
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

	Vertex verticesData[3];

	verticesData[0].m_v3Pos.x = 0.0f;  verticesData[0].m_v3Pos.y = 0.5f;  verticesData[0].m_v3Pos.z = 0.0f;
	verticesData[1].m_v3Pos.x = -0.5f;  verticesData[1].m_v3Pos.y = -0.5f;  verticesData[1].m_v3Pos.z = 0.0f;
	verticesData[2].m_v3Pos.x = 0.5f;  verticesData[2].m_v3Pos.y = -0.5f;  verticesData[2].m_v3Pos.z = 0.0f;

	//buffer object
	glGenBuffers(1, &vboId);
	glBindBuffer(GL_ARRAY_BUFFER, vboId);
	glBufferData(GL_ARRAY_BUFFER, sizeof(verticesData), verticesData, GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	shader = new Shader();
	shader->Init("../../Resources/Shaders/TriangleShader.vsh", "../../Resources/Shaders/TriangleShader.fsh");

	return 0;
}

int k = 0;
__VOID MainMenu::Update()
{
	if (k > -1)
		k++;
	SceneManager* a = SceneManager::GetInstance();
	if (k > 60)
	{
		k = -1;
		GamePlay* gamePlay = new GamePlay();
		gamePlay->Init();
		SceneManager::GetInstance()->Switch(gamePlay);
	}
}

__VOID MainMenu::Draw()
{
	glUseProgram(shader->m_Program);
	glBindBuffer(GL_ARRAY_BUFFER, vboId);
	int size;
	glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);
	if (shader->a_VertextPos != -1)
	{
		glEnableVertexAttribArray(shader->a_VertextPos);
		glVertexAttribPointer(shader->a_VertextPos, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
	}

	glDrawArrays(GL_TRIANGLES, 0, 3);

	glBindBuffer(GL_ARRAY_BUFFER, 0);
}

__VOID MainMenu::Exit()
{
	glDeleteBuffers(0, &vboId);
}